import datetime
from applications.extensions import db

class Article(db.Model):
    __tablename__ = 'blog_article'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment="文章ID")
    user_id = db.Column(db.Integer, db.ForeignKey('admin_user.id'))
    category_id = db.Column(db.Integer, db.ForeignKey('blog_category.id'))
    cover = db.Column(db.String(512), comment="文章封面")
    title = db.Column(db.String(256), comment="文章标题")
    author = db.Column(db.String(256), comment="文章作者")
    content = db.Column(db.Text, comment="文章内容")
    type = db.Column(db.Integer, comment="类型 (1原创 2转载 3翻译)")
    top = db.Column(db.Integer, comment="是否置顶 (0否 1是）")
    recommend = db.Column(db.Integer, comment="是否推荐 (0否 1是)")
    status = db.Column(db.Integer, comment="状态 (1公开 2私密 3评论可见)")
    is_del = db.Column(db.Integer, comment="是否删除(0未删,1删除)")
    create_at = db.Column(db.DateTime, default=datetime.datetime.now, comment='创建时间')
    update_at = db.Column(db.DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now, comment='更新时间')
    user = db.relationship("User", backref="articles")
    category = db.relationship("Category", backref="articles")
    tag = db.relationship('Tag', secondary="blog_article_tag", backref=db.backref('article'), lazy='dynamic')